﻿#ifndef AVAUDIORESAMPLE_H
#define AVAUDIORESAMPLE_H

#include <QObject>

extern "C"{
// FFmpeg
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavutil/pixfmt.h"
#include "libavutil/imgutils.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
}

class AVAudioResample : public QObject
{
    Q_OBJECT

public:
    explicit AVAudioResample(QObject *parent = nullptr);
    ~AVAudioResample();

    /**
     * @brief initialize
     *  初始化
     * @param out_ch_layout
     * @param out_sample_fmt
     * @param out_sample_rate
     * @param in_ch_layout
     * @param in_sample_fmt
     * @param in_sample_rate
     * @return
     */
    bool initialize(int64_t out_ch_layout, AVSampleFormat out_sample_fmt,
                    int out_sample_rate, int64_t in_ch_layout,
                    AVSampleFormat in_sample_fmt, int in_sample_rate);

    /**
     * @brief resample
     * @param frame
     * @return
     */
    AVFrame *resample(AVFrame *frame, int out_nb_samples);

    /**
     * @brief clear
     *  清理
     */
    void clear();

private:
    SwrContext *m_audio_convert_ctx; // 音频格式转换上下文

    enum AVSampleFormat m_out_sample_fmt; // 输出格式

};

#endif // AVAUDIORESAMPLE_H
